package com.vercon.moensmart.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.vercon.moensmart.R
import com.vercon.moensmart.adapter.base.BaseAdapter
import com.vercon.moensmart.databinding.ItemFollowMemberLayoutBinding
import com.vercon.moensmart.mode.response.FollowMember

class FollowMemberAdapter(context: Context?) : BaseAdapter<ItemFollowMemberLayoutBinding, FollowMember.ListDTO?>(context) {

    private var current_id : String? = null

    fun setCurrentId(id : String){
        this.current_id = id
        notifyDataSetChanged()
    }

    override fun baseViewHolder(parent: ViewGroup): BaseViewHolder {
        val binding : ItemFollowMemberLayoutBinding = ItemFollowMemberLayoutBinding.inflate(LayoutInflater.from(context),parent,false)
        return ViewHolder(binding)
    }

    override fun bindItemView(viewHolder: BaseViewHolder?, position: Int, data: FollowMember.ListDTO?, total: Int) {
        viewHolder?.mBinding?.tvMemberName?.text = data?.nickname
        if(current_id != null && current_id.equals(data?.pk)){
            viewHolder?.mBinding?.igSelect?.visibility = View.VISIBLE
            viewHolder?.mBinding?.llMain?.setBackgroundResource(R.drawable.bg_follow_member_select)
            viewHolder?.mBinding?.tvMemberName?.setTextColor(context?.resources!!.getColor(com.vercon.common.R.color.color_4D9DB4))
        }else{
            viewHolder?.mBinding?.igSelect?.visibility = View.GONE
            viewHolder?.mBinding?.llMain?.setBackgroundResource(R.drawable.bg_follow_member_no_select)
            viewHolder?.mBinding?.tvMemberName?.setTextColor(context?.resources!!.getColor(com.vercon.common.R.color.color_99B5BC))
        }
        viewHolder?.itemView?.setOnClickListener {
            mItemListener?.onItemClickListener(it,data,position)
        }
    }

    inner class ViewHolder(itemBinding: ItemFollowMemberLayoutBinding) : BaseViewHolder(itemBinding)
}